<!DOCTYPE html>
<html xmlns:layout="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
	layout:decorate="~{common/layoutAdmin}">

<head>
	<meta charset="UTF-8">
	<title>管理员信息</title>
</head>

<body>
	<div layout:fragment="fragment_body">
		<el-row :gutter="20">
			<el-col :span="24">
				<el-button type="primary" @click="openAdminInfo(null)">添 加</el-button>
				<el-table :data="adminInfos" border highlight-current-row style="width: 100%">
					<!-- -->
					<el-table-column prop="adminUser" label="登录名"></el-table-column>
					<el-table-column prop="adminPassword" label="登陆密码"></el-table-column>
					<el-table-column prop="adminName" label="昵称"></el-table-column>
					<el-table-column prop="adminTime" label="创建时间"></el-table-column>
					<el-table-column label="操作" width="160px">
						<template slot-scope="scope">
							<el-button @click="openAdminInfo(scope.row)" type="text" size="small">修 改</el-button>
							<el-popconfirm title="是否删除？" @confirm="delAdminInfo(scope.row.adminId)">
								<el-button slot="reference" type="text" size="small">删 除</el-button>
							</el-popconfirm>
						</template>
					</el-table-column>
				</el-table>
			</el-col>
		</el-row>
		<!--弹框-->
		<el-dialog :title="adminInfoForm.ttitle" :visible.sync="adminInfoForm.visible" width="30%">
			<el-form :model="adminInfoForm" :rules="adminInfoRules" ref="adminInfoForm" label-width="100px">
				<!-- -->
				<el-form-item label="登录名" prop="adminUser">
					<el-input v-model="adminInfoForm.adminUser"></el-input>
				</el-form-item>
				<el-form-item label="登陆密码" prop="adminPassword">
					<el-input v-model="adminInfoForm.adminPassword"></el-input>
				</el-form-item>
				<el-form-item label="昵称" prop="adminName">
					<el-input v-model="adminInfoForm.adminName"></el-input>
				</el-form-item>
				<el-form-item label="创建时间" prop="adminTime">
					<el-input v-model="adminInfoForm.adminTime"></el-input>
				</el-form-item>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button @click="closeAdminInfo">取 消</el-button>
				<el-button type="primary" @click="saveAdminInfo">保 存</el-button>
			</span>
		</el-dialog>
	</div>
</body>
<script type="text/javascript" layout:fragment="fragment_script">
	let vueData = {
		adminInfos: [],
		selectAdminInfo: null,
		adminInfoForm: {
			visible: false,
			ttitle: '新增/修改',
			adminId : '',
			adminUser : '',
			adminPassword : '',
			adminName : '',
			adminTime : '',
		},
		adminInfoQuery: {
			page: '',
			size: '',
		},
		adminInfoRules: {
			adminId: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			adminUser: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			adminPassword: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			adminName: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
			adminTime: [
				{required: true, message: '不能为空', trigger: 'blur'}
			],
		},
	}
	let vueMethods = {
		getAdminInfos() {
			let that = this
			postRequst('/admin/getAdminInfos', that.adminInfoQuery, true).then(function (resp) {
				that.adminInfos = resp.rows
				if (resp.rows && resp.rows.length > 0) {
					that.selectAdminInfo = resp.rows[0]
					that.getTopics()
				}
			})
		},
		openAdminInfo(row) {
			let that = this
			if (row) {
				that.adminInfoForm.ttitle = '修改'
				that.adminInfoForm.adminId = row.adminId
				that.adminInfoForm.adminUser = row.adminUser
				that.adminInfoForm.adminPassword = row.adminPassword
				that.adminInfoForm.adminName = row.adminName
				that.adminInfoForm.adminTime = row.adminTime
			} else {
				that.adminInfoForm.ttitle = '新增'
				that.adminInfoForm.adminId = ''
				that.adminInfoForm.adminUser = ''
				that.adminInfoForm.adminPassword = ''
				that.adminInfoForm.adminName = ''
				that.adminInfoForm.adminTime = ''
			}
			that.adminInfoForm.visible = true
		},
		closeAdminInfo() {
			this.$refs["adminInfoForm"].resetFields();
			this.adminInfoForm.visible = false
		},
		saveAdminInfo() {
			let that = this
			this.$refs["adminInfoForm"].validate((valid) => {
				if (valid) {
					postRequst('/admin/saveAdminInfo', that.adminInfoForm).then(function (resp) {
						if (resp.status == 0) {
							that.getAdminInfos()
							that.adminInfoForm.visible = false
							that.$message({message: resp.msg, type: "success"});
						} else {
							that.$message({message: resp.msg, type: "error"});
						}
					})
				}
			});
		},
		delAdminInfo(adminId) {
			let that = this
			postRequst('/admin/delAdminInfo', {adminId: adminId}, true).then(function (resp) {
				if (resp.status == 0) {
					that.getAdminInfos()
					that.$message({message: resp.msg, type: "success"});
				} else {
					that.$message({message: resp.msg, type: "error"});
				}
			})
		},
	}
	function vueCreated() {
		let that = this
		that.getAdminInfos()
	}
</script>

</html>